package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺状态接口")
@RestController("adminShopStatusController")
@RequestMapping("/admin/shop")
public class ShopStatusController {
    @Autowired
    private RedisTemplate redisTemplate;

    private final static String SHOP_STATUS = "SHOP_STATUS";

    // 修改店铺营业信息
    @PutMapping("/{status}")
    @ApiOperation("修改营业状态")
    public Result<String> changShopStatus(@PathVariable Integer status) {
        log.info("status: {}", status);
        ValueOperations valueOperations = redisTemplate.opsForValue();

        valueOperations.set(SHOP_STATUS, status);

        return Result.success();
    }

    @ApiOperation("查询店铺营业状态")
    @GetMapping("/status")
    public Result getStatus(){
        //调用redisTemplate，从redis中查询指定的key，获取营业状态
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        log.info("查询店铺营业状态：{}", status);
        //返回结果
        return Result.success(status);
    }
}
